home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 126-150 / disk_136 / asmtoolbox / test3.asm < prev    next >
Assembly Source File  |  1992-05-06  |  6KB  |  175 lines

  1. ; TEST3.ASM by Warren A. Ring
  2. ;
  3. ; This program shows how the warlib disk I/O routines work.  You can open,
  4. ; create, rename, and delete files.  Once open, you can close the file, or
  5. ; read, write, or seek in it.  You can also display or modify records.
  6. ; In this example, we can create files with 16-byte fixed record lengths.
  7. ; Each record contains a phrase padded with spaces to make it 16 characters
  8. ; long.  After exiting this program, you can see the exact hex bytes by
  9. ; entering "1>type <filename> opt h", where <filename> is the name of the
  10. ; file you created.
  11.  
  12.    section code
  13.  
  14.    include "macros.asm"
  15.  
  16.    Start                   ;Perform starting housekeeping
  17. X1
  18.    Display <'O)pen, C)reate, R)ename, D)elete, E)xit: '>
  19.    ReadCon #Selection      ;Get a selection from the console
  20.  
  21.    StrCmp  #Selection,#O   ;If the selection is not "O",
  22.    BNE     X2              ; then jump to X2
  23.    Display <'Which file? '>
  24.    ReadCon #Filename1      ;Get a file name from the console
  25.    Open    #Filename1,File1;Try to open the file
  26.    BEQ     X1A             ;If the file did not open, then jump to X1A
  27.    Display <'The file is open',LF>
  28.    BRA     X10             ;Jump to X10
  29. X1A
  30.    Display <'There is no such file',LF>
  31.    BRA     X1              ;Jump to X1
  32.  
  33. X2
  34.    StrCmp  #Selection,#C   ;If the selection is not "C",
  35.    BNE     X3              ; then jump to X3
  36.    Display <'Which file? '>
  37.    ReadCon #Filename1      ;Get a file name from the console
  38.    Create  #Filename1,File1;Try to create the file
  39.    BEQ     X2A             ;If the file was not created, then jump to X2A
  40.    Display <'The file is open',LF>
  41.    BRA     X10             ;Jump to X10
  42. X2A
  43.    Display <'I cannot create it',LF>
  44.    BRA     X1              ;Jump to X1
  45.  
  46. X3
  47.    StrCmp  #Selection,#R   ;If the selection is not "R",
  48.    BNE     X4              ; then jump to X4
  49.    Display <'Which file? '>
  50.    ReadCon #Filename1      ;Get the old file name from the console
  51.    Display <'New filename? '>
  52.    ReadCon #Filename2      ;Get the new file name
  53.    Rename  #Filename1,#Filename2;Try to rename the file
  54.    BEQ     X3A             ;If the file was not renamed, then jump to X3A
  55.    Display <'The file is renamed',LF>
  56.    BRA     X1              ;Jump to X1
  57. X3A
  58.    Display <'I cannot rename it',LF>
  59.    BRA     X1              ;Jump to X1
  60.  
  61. X4
  62.    StrCmp  #Selection,#D   ;If the selection was not "D",
  63.    BNE     X5              ; then jump to X5
  64.    Display <'Which file? '>
  65.    ReadCon #Filename1      ;Get a file name from the console
  66.    Delete  #Filename1      ;Try to delete the file
  67.    BEQ     X4A             ;If the file was not deleted, then jump to X4A
  68.    Display <'The file is deleted',LF>
  69.    BRA     X1              ;Jump to X1
  70. X4A
  71.    Display <'I cannot delete it',LF>
  72.    BRA     X1              ;Jump to X1
  73.  
  74. X5
  75.    StrCmp  #Selection,#E   ;If the selection was not "E",
  76.    BNE     X6              ; then jump to X6
  77.    Display <'Exiting...',10>
  78.    BRA     X99             ;Jump to X99
  79.  
  80. X6
  81.    BRA     X1              ;Jump to X1
  82.  
  83. X10
  84.    Display <'C)lose, R)ead, W)rite, D)isplayRec, M)odifyRec, S)eek: '>
  85.    ReadCon #Selection      ;Get a selection from the console
  86.    StrCmp  #Selection,#C   ;If the selection was not "C",
  87.    BNE     X11             ; then jump to X11
  88.    Close   File1           ;Try to close the file (ignore any errors)
  89.    BRA     X1              ;Jump to X1
  90.  
  91. X11
  92.    StrCmp  #Selection,#R   ;If the selection was not "R",
  93.    BNE     X12             ; then jump to X12
  94.    Read    File1,#Record1  ;Read a record from the file
  95.    ADDQ.L  #1,RecNum1      ;Increment the record number
  96.    StrLen  #Record1        ;If there were some bytes read,
  97.    BNE     X10             ; then jump to X10
  98.    Display <'Unwritten record',LF>
  99.    BRA     X10             ;Jump to X10
  100.  
  101. X12
  102.    StrCmp  #Selection,#W   ;If the selection was not "W",
  103.    BNE     X13             ; then jump to X13
  104.    ADDQ.L  #1,RecNum1      ;Increment the record number
  105.    Write   File1,#Record1  ;Write a record to the file
  106.    BGT     X10             ;If any bytes were written, then jump to X10
  107.    Display <'Error',LF>
  108.    BRA     X10             ;Jump to X10
  109.  
  110. X13
  111.    StrCmp  #Selection,#D   ;If the selection was not "D",
  112.    BNE     X14             ; then jump to X14
  113.    Display <'Record '>
  114.    ItoA    RecNum1,#Selection;Convert the record number to ASCII
  115.    WritCon #Selection      ;Display the record number
  116.    Display <', the word is "'>
  117.    WritCon #Record1        ;Display the record
  118.    Display <'"',LF>
  119.    BRA     X10             ;Jump to X10
  120.  
  121. X14
  122.    StrCmp  #Selection,#M   ;If the selection was not "W",
  123.    BNE     X15             ; then jump to X15
  124.    Display <'Enter a new word: '>
  125.    ReadCon #Word           ;Get a line from the console
  126.    StrCpy  #Spaces,#Record1;Pad the line with spaces to make it
  127.    StrCpy  #Word,#Record1  ; 16 chars long
  128.    MOVE.L  #16,D0          ;Assign the line length to 16 bytes
  129.    MOVE.L  D0,Record1+4
  130.    BRA     X10             ;Jump to X10
  131.  
  132. X15
  133.    StrCmp  #Selection,#S   ;If the selection was not "S",
  134.    BNE     X16             ; then jump to X16
  135.    Display <'Enter the record number: '>
  136.    ReadCon #Selection      ;Get a record number from the console
  137.    AtoI    #Selection,RecNum1;Convert the record number from ASCII to binary
  138.    MOVE.L  RecNum1,D0      ;Convert the record number to a file offset
  139.    LSL.L   #4,D0           ; (by multiplying the record number by 16)
  140.    MOVE.L  D0,File1Offset
  141.    Seek    File1,File1Offset;Seek to the file offset
  142.    BRA     X10             ;Jump to X10
  143.  
  144. X16
  145.    BRA     X10             ;Jump to X10
  146.  
  147. X99
  148.    Exit                ;Perform ending housekeeping, and exit
  149.  
  150.    include "warlib.asm"
  151.  
  152.    section data
  153.  
  154.        String  C,'C'
  155.        String  D,'D'
  156.        String  E,'E'
  157.        String  M,'M'
  158.        String  O,'O'
  159.        String  R,'R'
  160.        String  S,'S'
  161.        String  W,'W'
  162.        String  Spaces,<'                '>
  163.  
  164.        StrBuf  Filename1,16
  165.        StrBuf  Filename2,16
  166.        StrBuf  Word,16
  167.        StrBuf  Record1,16
  168.        StrBuf  Selection,16
  169.  
  170. File1          DC.L    0
  171. RecNum1        DC.L    0
  172. File1Offset    DC.L    0
  173.  
  174.    end
  175.